<template>
	<view class="page">
		<view class="order-title-block">
			<view class="order-name" @click="toJijin">
				{{order.name}}
			</view>
			<view class="buy-doing" v-if="order.status == 0">
				<view class="MoneyOrNumber">
					{{order.buyMoney}}元
				</view>
				<text class="text">份额待确认</text>
				<view class="predict">
					预计买入份额为{{(order.buyMoney/newest_guzhi).toFixed(2)}}份
				</view>
			</view>
			<view class="buy-finish" v-if="order.status == 1">
				<view class="MoneyOrNumber">
					{{order.buyMoney}}元
				</view>
				<text class="text">买入成功</text>
			</view>
			<view class="sell-doing" v-if="order.status == 3">
				<view class="MoneyOrNumber">
					{{order.buyNumber}}份
				</view>
				<text class="text">金额待确认</text>
				<view class="predict">
					预计卖出金额为{{(order.buyNumber*newest_guzhi).toFixed(2)}}元
				</view>
			</view>
			<view class="sell-finish" v-if="order.status == 4">
				<view class="MoneyOrNumber">
					{{order.buyNumber}}份
				</view>
				<text class="text">卖出成功</text>
			</view>
		</view>
		
		<view class="order-details">
			<view class="buy-doing-detail" v-if="order.status == 0">
				<view class="detail" style="color: #000000;">
					买入信息
				</view>
				<view class="detail">
					<view class="detail-left">
						买入产品
					</view>
					<view class="detail-right"  @click="toJijin">
						{{order.name}}
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						买入金额
					</view>
					<view class="detail-right">
						{{order.buyMoney}}元
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						可赎天数
					</view>
					<view class="detail-right">
						{{order.freeDay}}天
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						买入时间
					</view>
					<view class="detail-right">
						{{order.gmtModified.split('T')[0]}}
					</view>
				</view>
			</view>
			<view class="buy-finish-detail" v-if="order.status == 1">
				<view class="detail" style="color: #000000;">
					买入信息
				</view>
				<view class="detail">
					<view class="detail-left">
						买入产品
					</view>
					<view class="detail-right" @click="toJijin">
						{{order.name}}
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						买入金额
					</view>
					<view class="detail-right">
						{{order.buyMoney}}元
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						确认份额
					</view>
					<view class="detail-right">
						{{order.buyNumber}}份
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						确认净值
					</view>
					<view class="detail-right">
						{{order.buyPrice}}
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						买入时间
					</view>
					<view class="detail-right">
						{{order.gmtModified.split('T')[0]}}
					</view>
				</view>
			</view>
			<view class="sell-doing-detail" v-if="order.status == 3">
				<view class="detail" style="color: #000000;">
					卖出信息
				</view>
				<view class="detail">
					<view class="detail-left">
						卖出产品
					</view>
					<view class="detail-right" @click="toJijin">
						{{order.name}}
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						卖出份额
					</view>
					<view class="detail-right">
						{{order.buyNumber}}份
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						卖出时间
					</view>
					<view class="detail-right">
						{{order.gmtModified.split('T')[0]}}
					</view>
				</view>
			</view>
			<view class="sell-finish-detail" v-if="order.status == 4">
				<view class="detail" style="color: #000000;">
					卖出信息
				</view>
				<view class="detail">
					<view class="detail-left">
						卖出产品
					</view>
					<view class="detail-right" @click="toJijin">
						{{order.name}}
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						卖出份额
					</view>
					<view class="detail-right">
						{{order.buyNumber}}份
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						确认净值
					</view>
					<view class="detail-right">
						{{order.buyPrice}}
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						确认金额
					</view>
					<view class="detail-right">
						{{order.sellMoney}}元
					</view>
				</view>
				
				<view class="detail">
					<view class="detail-left">
						卖出时间
					</view>
					<view class="detail-right">
						{{order.gmtModified.split('T')[0]}}
					</view>
				</view>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	
	var _self
	
	export default {
		data() {
			return {
				newest_guzhi: 0,
				order: {} 
			}
		},
		onLoad(data) {
			_self = this
			var orderId = data.orderId 
			if(orderId != null && orderId != undefined){
				console.log('orderId'+orderId)
				this.findOrder(data.orderId) 
			}
		},
		methods: {
			toJijin() {
				//跳转到基金页面
				uni.navigateTo({
					url: '../me/detail/detail?code='
					+_self.order.code+'&name='+_self.order.name,
					animationType: 'pop-in',
					animationDuration: 200
				})
			},
			async findOrder(orderId) {
				if(orderId != null && orderId != undefined){
					uni.showLoading({
						title:'查询中...',
						mask:false
					})
					_self.order = await this.store.getOrderDetail(orderId)
					var result = await this.store.getNewestNumber(_self.order.code)
					_self.newest_guzhi = result.guzhi
					uni.hideLoading()
				}
			}
		}
	}
</script>

<style>
	@import url("order.css");
</style>
